<?php
/**
 * Created by PhpStorm.
 * User: xuechunxuan
 * Date: 2018/10/18
 * Time: 11:18
 */
namespace app\index\model;

use think\Db;

class Share extends Base{
    public function __construct($data = [])
    {
        $this->setTableName("user_share_detail");
    }

    /*
     * 写入明细并增加用户余额
     * */
    public function readDetailAndIncUserAmount($data){
        // 启动事务
        Db::startTrans();
        try {
            Db::name($this->getTableName())->insert($data);
            Db::name("seller_consume")->where(['id'=>$data['qrcode_id']])->setInc("uv");//海报关注uv+1
            Db::name("user")->where(['openid'=>$data['openid']])->setInc("amount",$data['price']);
            $result=true;
            // 提交事务
            Db::commit();
        } catch (\Exception $e) {
            $result=false;
            // 回滚事务
            Db::rollback();
        }
        return $result;
    }
}